import socket

# 初始化服务端socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 绑定ip和port
server_socket.bind(("127.0.0.1", 8887))
# listener
server_socket.listen(5)
# 接受客户端连接
client_socket, client_addr = server_socket.accept()
print(client_addr)
# 接受客户端的信息
msg = client_socket.recv(1024).decode()
while msg:
    if msg != '':
        print("接收到客户端信息：", msg)
        # 阻塞
    send_msg = input("请输入发送给客户端的信息：")
    if send_msg == "bye":
        break
    client_socket.send(send_msg.encode())

    print("发送成功，等待客户端信息")
    msg = client_socket.recv(1024).decode()
client_socket.close()
server_socket.close()
